/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Comun;

import Fuente.busqueda;
import FuenteDeDatos.DataSource;
import com.mysql.jdbc.Connection;
import java.awt.Cursor;
import java.net.URL;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.swing.JRViewer;

/**
 *
 * @author luisramirezmartinez SAMI 2011
 *
 */
public class rptLaucher {
    private busqueda bus;
    private DataSource ds;
    public  Connection conn;
    private String rpt;
    public rptLaucher(busqueda bus, DataSource ds, String rpt) {
        this.bus=bus;
        this.ds=ds;
        this.rpt=rpt;
        
        
    }
    
    public void lanzar(){
           
                bus.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                System.out.println(rpt);
                URL urlReportes = bus.getClass().getResource ("/Reportes/"+rpt+".jasper");
                String urlImagenes = ""+this.getClass().getResource("/Reportes/Saic.png");
                //URL urlReportes =  "/Users/luisramirezmartinez/NetBeansProjects/SAIC2/src/Reportes";
                JasperReport rpt = null;
                Map<String, Object> parameters = new HashMap<String, Object>();
                JasperPrint jasperPrint = null;
                parameters.put("pImagen", urlImagenes);
                try {
                    rpt = (JasperReport) JRLoader.loadObject(urlReportes);
                } catch (JRException ex) {
                   
                }                                                  
                    conn = (Connection) this.ds.getConexion();
                
                               
                try {
                    jasperPrint = JasperFillManager.fillReport(rpt, parameters, conn);
                } catch (JRException ex) {
                   
                }

                JDialog viewer = new JDialog(new JFrame(), "Vista previa del reporte", true);
                viewer.setSize(1100, 700);
                viewer.setLocationRelativeTo(null);
                JRViewer jrv = new JRViewer(jasperPrint);
                viewer.getContentPane().add(jrv);
                viewer.setVisible(true);


                this.bus.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    
    
    
    }
}
